﻿unit USingle;

interface

  uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UBaseTemplate, System.ImageList, Vcl.ImgList, System.Actions, Vcl.ActnList,
    Vcl.ComCtrls, Vcl.ToolWin, Vcl.DBActns, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, frxDesgn,
    FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, Data.DB,
    FireDAC.Comp.DataSet, FireDAC.Comp.Client, Vcl.Menus, frxDBSet, frxClass, System.strutils, DBGridEhImpExp,
     Vcl.Buttons, Data.Win.ADODB, Excel2000, Vcl.OleServer, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit, dxSkinsCore, dxSkinsDefaultPainters,
  cxTextEdit, cxMaskEdit, cxDropDownEdit, cxCalendar, cxDBEdit;

  type
    TfrmSingle = class(Tfrmbasetemplate)
      ToolBar1: TToolBar;
      ToolButton1: TToolButton;
      ToolButton2: TToolButton;
      ToolButton3: TToolButton;
      ToolButton4: TToolButton;
      ToolButton5: TToolButton;
      tbseparator1: TToolButton;
      ToolButton7: TToolButton;
      ToolButton8: TToolButton;
      ToolButton9: TToolButton;
      tbseparator2: TToolButton;
      ToolButton11: TToolButton;
      ToolButton12: TToolButton;
      ToolButton13: TToolButton;
      tbseparator3: TToolButton;
      ToolButton15: TToolButton;
      ToolButton16: TToolButton;
      ToolButton17: TToolButton;
      ToolButton18: TToolButton;
      tbseparator4: TToolButton;
      ToolButton20: TToolButton;
      dsMaster: TDataSource;
      ToolButton21: TToolButton;
      pmPrint: TPopupMenu;
      frxDBDSMaster: TfrxDBDataset;
      frxDBDSModuleReport: TfrxDBDataset;
      ToolButton6: TToolButton;
      ToolButton10: TToolButton;
      ToolButton14: TToolButton;
      ToolButton19: TToolButton;
      PMSearch: TPopupMenu;
      SaveDialog1: TSaveDialog;
      ToolButton22: TToolButton;
      ToolButton23: TToolButton;
      frxReport1: TfrxReport;
      FDQryModuleReport: TFDQuery;
      FDQryMaster: TFDQuery;
      FDUPSQLMaster: TFDUpdateSQL;
      FDQrySQL: TFDQuery;
      FDQrySQLmodule_code: TWideStringField;
      FDQrySQLQuery_Name: TWideStringField;
      FDQrySQLQuery_Sql: TWideStringField;
      FDQrySQLQuery_Where: TWideStringField;
      FDQrySQLQuery_sort: TWideStringField;
      FDQrySQLQuery_id: TFDAutoIncField;
      FDQryModuleFields: TFDQuery;
      ActImport: TAction;
      ToolButton24: TToolButton;
      pmImport: TPopupMenu;
      N1: TMenuItem;
      N2: TMenuItem;
      N3: TMenuItem;
      pmreportDesign: TPopupMenu;
      N6: TMenuItem;
      N7: TMenuItem;
    FDQryModuleQuery: TFDQuery;
    FDQryModuleReportMDR_ID: TFDAutoIncField;
    FDQryModuleReportMOD_Code: TStringField;
    FDQryModuleReportMDR_CODE: TStringField;
    FDQryModuleReportMDR_Name: TStringField;
    FDQryModuleReportMDR_IfDefault: TBooleanField;
    FDQryModuleReportMDR_IfUsed: TBooleanField;
    FDQryModuleReportMDR_Remark: TStringField;
    FDQryModuleReportMDR_Data: TBlobField;
    FDQryModuleReportMDR_Index: TIntegerField;
    FDQryModuleReportMDR_CreateDate: TSQLTimeStampField;
    FDQryModuleReportMDR_ModifyDate: TSQLTimeStampField;
      procedure FormCreate(Sender: TObject);
      procedure FormShow(Sender: TObject);
      procedure ActAddExecute(Sender: TObject);
      procedure ActEditExecute(Sender: TObject);
      procedure ActCancelExecute(Sender: TObject);
      procedure ActPostExecute(Sender: TObject);
      procedure ActDelExecute(Sender: TObject);
      procedure ActPrintExecute(Sender: TObject);
      procedure ActDesignExecute(Sender: TObject);
      procedure ActCheckExecute(Sender: TObject);
      procedure ActApproveExecute(Sender: TObject);
      procedure ActAuditExecute(Sender: TObject);
      procedure ActRefreshExecute(Sender: TObject);
      procedure ActExitExecute(Sender: TObject);
      procedure ActUncheckExecute(Sender: TObject);
      procedure ActUnApproveExecute(Sender: TObject);
      procedure ActUnAuditExecute(Sender: TObject);
      procedure ActStopExecute(Sender: TObject);
      procedure ActUnStopExecute(Sender: TObject);
      procedure ActvalidExecute(Sender: TObject);
      procedure ActinvalidExecute(Sender: TObject);
      procedure ActExportExecute(Sender: TObject);
      procedure ActCloseExecute(Sender: TObject);
      procedure ActUncloseExecute(Sender: TObject);
      procedure FDQryMasterAfterScroll(DataSet: TDataSet);
      procedure FDQryMasterNewRecord(DataSet: TDataSet);
      procedure N3Click(Sender: TObject);
      procedure FDQryModuleReportNewRecord(DataSet: TDataSet);
      procedure N6Click(Sender: TObject);
    private
      { Private declarations }
      procedure AddReportMenu();
      procedure QueryAndGridSet();
      procedure AddReportVariables(FrpPubPrint: TfrxReport);
      procedure pmPrintClick(Sender: TObject);
      procedure pmDesignClick(Sender: TObject);
      procedure frxReportGetValue(const VarName: string; var Value: Variant);
      function frxSaveReportEvent(Report: TfrxReport; SaveAs: Boolean): Boolean;
    public
      { Public declarations }
      Event: string;
      FOldSearchSQL: string;
      FShowOpen: Boolean;
      IfAutoPrint: Boolean; // 是否需要自动创建打印菜单
      FOldKey: String;
      editreportfilename: String; // 保存报表名字，方便保存报表时

    protected
      procedure DoBeforePrint; virtual; // 打印前进行操作；
      procedure DoAfterPrint; virtual; // 打印后进行操作；
    end;

  var
    frmSingle: TfrmSingle;

implementation

  Uses Udm, Ucommon, Umain, UAddReport, UReportPreview;
{$R *.dfm}

  procedure TfrmSingle.ActAddExecute(Sender: TObject);
  ResourceString
    RaiseStr1 = '此模块未正确设置数据源脚本，不能操作！';
  begin
    if FDQryMaster.SQL.Text = '' then
    begin
      showmessage(RaiseStr1);
      abort;
    end;

    if not FDQryMaster.Active then
    begin
      FDQryMaster.Open;
    end
    else
    begin
      FDQryMaster.Refresh;
    end;

    inherited;
    FDQryMaster.append;

  end;

  procedure TfrmSingle.ActApproveExecute(Sender: TObject);
  ResourceString
    RaiseStr1 = '此记录未提交，不能作审核操作！';
  begin
    if StrCheckUser <> '' then
    begin
      if FDQryMaster.FieldByName(StrCheckUser).AsString = '' then
      begin
        showmessage(RaiseStr1);
        abort;
      end;

    end;
    inherited;
    if StrApporeUser = '' then
    begin
      showmessage('系统未设置模块中的【审核人】字段内容，请与世鸿网络科技联系');
      abort;
    end;
    if StrApporetime = '' then
    begin
      showmessage('系统未设置模块中的【审核时间】字段内容，请与世鸿网络科技联系');
      abort;
    end;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;
    if IfApprove and (StrApporeUser <> '') and (StrApporetime <> '') then
    begin
      FDQryMaster.Edit;
      FDQryMaster.FieldByName(StrApporeUser).Value := UserName;
      FDQryMaster.FieldByName(StrApporetime).Value := now();
      FDQryMaster.Post;

    end
    else
    begin
      showmessage('本系统不需要审核此数据或是未设置正确的【审核】内容，请与系统管理员联系');
    end;
    { if StrKeyField <> '' then
      DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
      .AsString]))
      else
      DM.SM_LOG(TAction(Sender).Caption); }
    FDQryMasterAfterScroll(FDQryMaster);
  end;

  procedure TfrmSingle.ActAuditExecute(Sender: TObject);
  ResourceString
    RaiseStr1 = '此记录未审核，不能作记账操作！';
  begin
    if StrApporeUser <> '' then
    begin
      if FDQryMaster.FieldByName(StrApporeUser).AsString = '' then
      begin
        showmessage(RaiseStr1);
        abort;
      end;
    end;
    inherited;
    if StrAuditUser = '' then
    begin
      showmessage('系统未设置模块中的【记账人】字段内容，请与世鸿网络科技联系');
      abort;
    end;
    if StrAudittime = '' then
    begin
      showmessage('系统未设置模块中的【记账时间】字段内容，请与世鸿网络科技联系');
      abort;
    end;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;
    if IfAuditor and (StrAuditUser <> '') and (StrAudittime <> '') then
    begin
      FDQryMaster.Edit;
      FDQryMaster.FieldByName(StrAuditUser).Value := UserName;
      FDQryMaster.FieldByName(StrAudittime).Value := now();
      FDQryMaster.Post;
    end
    else
    begin
      showmessage('本系统不需要记账此数据或是未设置正确的【记账】内容，请与系统管理员联系');
    end;
    { if StrKeyField <> '' then
      DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
      .AsString]))
      else
      DM.SM_LOG(TAction(Sender).Caption); }
    FDQryMasterAfterScroll(FDQryMaster);
  end;

  procedure TfrmSingle.ActCancelExecute(Sender: TObject);
  begin
    inherited;

    if FDQryMaster.CachedUpdates then
    begin
      FDQryMaster.CancelUpdates();
    end
    else
      FDQryMaster.Cancel;
    FDQryMaster.Refresh;
  end;

  procedure TfrmSingle.ActCheckExecute(Sender: TObject);
  begin
    inherited;
    if StrCheckUser = '' then
    begin
      showmessage('系统未设置模块中的【提交人】字段内容，请与世鸿网络科技联系');
      abort;
    end;
    if StrCheckTime = '' then
    begin
      showmessage('系统未设置模块中的【提交时间】字段内容，请与世鸿网络科技联系');
      abort;
    end;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;

    if IfCheck and (StrCheckUser <> '') and (StrCheckTime <> '') then
    begin
      FDQryMaster.Edit;
      FDQryMaster.FieldByName(StrCheckUser).Value := UserName;
      FDQryMaster.FieldByName(StrCheckTime).Value := now();
      FDQryMaster.Post;
      FDQryMaster.RefreshRecord;

    end
    else
    begin
      showmessage('本系统不需要提交此数据或是未设置正确的【提交】内容，请与系统管理员联系');
    end;
    { if StrKeyField <> '' then
      DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
      .AsString]))
      else
      DM.SM_LOG(TAction(Sender).Caption); }
    FDQryMasterAfterScroll(FDQryMaster);
  end;

  procedure TfrmSingle.ActCloseExecute(Sender: TObject);
  ResourceString
    RaiseStr1 = '此记录未提交，不能作完结操作！';
  begin
    if StrCheckUser <> '' then
    begin
      if FDQryMaster.FieldByName(StrCheckUser).AsString = '' then
      begin
        showmessage(RaiseStr1);
        abort;
      end;

    end;
    inherited;
    if StrCloseUser = '' then
    begin
      showmessage('系统未设置模块中的【完结人】字段内容，请与世鸿网络科技联系');
      abort;
    end;
    if StrClosetime = '' then
    begin
      showmessage('系统未设置模块中的【完结时间】字段内容，请与世鸿网络科技联系');
      abort;
    end;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;

    if IfCheck and (StrCloseUser <> '') and (StrClosetime <> '') then
    begin
      FDQryMaster.Edit;
      FDQryMaster.FieldByName(StrCloseUser).Value := UserName;
      FDQryMaster.FieldByName(StrClosetime).Value := now();
      FDQryMaster.Post;
    end
    else
    begin
      showmessage('本系统不需要完结此数据或是未设置正确的【完结】内容，请与系统管理员联系');
    end;
    { if StrKeyField <> '' then
      DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
      .AsString]))
      else
      DM.SM_LOG(TAction(Sender).Caption); }
    FDQryMasterAfterScroll(FDQryMaster);
  end;

  procedure TfrmSingle.ActDelExecute(Sender: TObject);
  ResourceString
    RaiseStr2 = '您真的要删除当前内容吗？';
  begin
    if not FDQryMaster.Active then
      abort;
    if FDQryMaster.RecordCount = 0 then
    begin
      showmessage(format(NoRecordMSG, [TAction(Sender).Caption]));
      abort;
    end;
    if StrCheckUser <> '' then
    begin
      if FDQryMaster.FieldByName(StrCheckUser).AsString <> '' then
      begin
        showmessage(format(NotCanWorkMSG, ['提交', TAction(Sender).Caption]));
        abort;
      end;
    end;
    inherited;
    if MessageDlg(RaiseStr2, mtConfirmation, [mbyes, mbno], 0) = mryes then
    begin
      { if StrKeyField <> '' then
        DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
        .AsString]))
        else
        DM.SM_LOG(TAction(Sender).Caption); }
      FDQryMaster.delete;
      // 如果是批量保存
      if FDQryMaster.CachedUpdates then
        FDQryMaster.ApplyUpdates;
    end;
  end;

  procedure TfrmSingle.ActEditExecute(Sender: TObject);
  ResourceString
    RaiseStr2 = '此记录已提交，不能作修改操作';
  begin
    if not FDQryMaster.Active then
      abort;
    if FDQryMaster.RecordCount = 0 then
    begin
      showmessage(format(NoRecordMSG, [TAction(Sender).Caption]));
      abort;
    end;
    if StrCheckUser <> '' then
    begin
      if FDQryMaster.FieldByName(StrCheckUser).AsString <> '' then
      begin
        showmessage(format(NotCanWorkMSG, ['提交', TAction(Sender).Caption]));
        abort;
      end;
    end;
    inherited;

    FDQryMaster.Edit;
    { if StrKeyField <> '' then
      DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
      .AsString]))
      else
      DM.SM_LOG(TAction(Sender).Caption); }
  end;

  procedure TfrmSingle.ActPostExecute(Sender: TObject);
  var
    I: integer;
    columncount: integer;
  begin
    ToolBar1.SetFocus;
    if IfAutoNumber and (FDQryMaster.FieldByName(StrKeyField).AsString = '') then
      FDQryMaster.FieldByName(StrKeyField).AsString := DM.CreateNo(Rightstr(Self.name, 5), '');

    columncount := FDQryMaster.FieldCount;
    for I := 0 to columncount - 1 do
    begin
      FDQryMaster.Fields[I].FocusControl;
      if FDQryMaster.Fields[I].Required and (FDQryMaster.Fields[I].IsNull) then
      begin
        raise Exception.Create(format('字段【%s】内容不能为空！', [FDQryMaster.Fields[I].DisplayLabel]));
      end;
    end;
    inherited;
    // 如果是在编辑状态进行保存
    if FDQryMaster.state in dseditmodes then
    begin
      FDQryMaster.Post;
    end;
    { if StrKeyField <> '' then
      DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
      .AsString]))
      else
      DM.SM_LOG(TAction(Sender).Caption); }
    // 如果是批量保存
    if FDQryMaster.CachedUpdates then
    begin
      FDQryMaster.ApplyUpdates(0);
      FDQryMaster.CommitUpdates;
    end;
   // FDQryMaster.Refresh;
  end;

  procedure TfrmSingle.ActPrintExecute(Sender: TObject);
  ResourceString
    RaiseStr1 = '该记录还未【提交】，不能进行【打印】！';
    RaiseStr4 = '该记录已【取消】，不能进行【打印】！';
  var
    reportstream: TMemoryStream;
  begin

    if (not FDQryMaster.Active) or FDQryMaster.IsEmpty then
    begin
      showmessage(format(NoRecordMSG, [TAction(Sender).Caption]));
      abort;
    end;
    inherited;

    try
      if not FDQryModuleReport.Locate('MDR_IfDefault', 1, []) then
      begin
        showmessage(NoPrintDefaultTemplate);
        abort;
      end;

      editreportfilename := FDQryModuleReportMDR_CODE.AsString + '_' + Trim(FDQryModuleReportMDR_Name.AsString);

      // 已取消的不能打印
      if Trim(StrCancelUser) <> '' then
      begin
        if FDQryMaster.FieldByName(Trim(StrCancelUser)).AsString <> '' then
        begin
          showmessage(format(NotCanWorkMSG, ['取消', TAction(Sender).Caption]));
          abort;
        end;
      end;
      // 未提交的不能打印
      if Trim(StrCheckUser) <> '' then
      begin
        if FDQryMaster.FieldByName(Trim(StrCheckUser)).AsString = '' then
        begin
          showmessage(format(NotOperationMSG, ['提交', TAction(Sender).Caption]));
          abort;
        end;
      end;

      frxReport1.Clear;
      if not FDQryModuleReportMDR_Data.IsNull then
      begin
        reportstream := TMemoryStream.Create;
        FDQryModuleReport.FetchBlobs;
        FDQryModuleReportMDR_Data.SaveToStream(reportstream);
        reportstream.Position := 0;
        frxReport1.LoadFromStream(reportstream);
      end;

      AddReportVariables(frxReport1);
      frxReport1.OnGetValue := frxReportGetValue;
      DoBeforePrint;
      frmReportPreview := TfrmReportPreview.Create(Self);
      frmReportPreview.FastRP := frxReport1;
      frxReport1.Preview := frmReportPreview.frxPreview;
      frxReport1.ShowReport;
      frmReportPreview.ShowModal;
    finally
      { if StrKeyField <> '' then
        DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
        .AsString]))
        else
        DM.SM_LOG(TAction(Sender).Caption); }
      DoAfterPrint;
      frmReportPreview.Free;
      frmReportPreview := nil;

    end;

  end;

  procedure TfrmSingle.AddReportMenu;
  var
    TmpItem, subItem: TMenuItem;
  begin
    // 加打印报表菜单及设计报表菜单
    if ActPrint.Visible or ActDesign.Visible then
    begin
      if not FDQryModuleReport.Active then
      begin
        FDQryModuleReport.Close;
        FDQryModuleReport.Params.Items[0].Value := Self.name;
        FDQryModuleReport.Open;
      end;

      FDQryModuleReport.First;
      pmPrint.Items.Clear;
      while not FDQryModuleReport.Eof do
      begin
        TmpItem := TMenuItem.Create(Self);
        TmpItem.name := 'R' + Trim(FDQryModuleReportMDR_CODE.AsString);
        TmpItem.Caption := Trim(FDQryModuleReportMDR_Name.AsString);
        TmpItem.OnClick := pmPrintClick;
        // 是不是可以先判断再创建
        if pmPrint.Items.IndexOf(TmpItem) = -1 then
          pmPrint.Items.add(TmpItem)
        else
          TmpItem.Free;

        TmpItem := TMenuItem.Create(Self);
        TmpItem.name := 'D' + Trim(FDQryModuleReportMDR_CODE.AsString);
        TmpItem.Caption := '设计:' + Trim(FDQryModuleReportMDR_Name.AsString);
        TmpItem.OnClick := pmDesignClick;
        // 是不是可以先判断再创建
        if pmPrint.Items.IndexOf(TmpItem) = -1 then
          pmreportDesign.Items.add(TmpItem)
        else
          TmpItem.Free;

        FDQryModuleReport.Next;
      end;
      // 打印按钮
      ActPrint.Visible := pmPrint.Items.Count > 0;
      if pmPrint.Items.Count > 0 then
      begin
        ToolButton13.Style := tbsDropDown;
        ToolButton13.DropdownMenu := pmPrint;
      end;
      // 设计按钮
      ActDesign.Visible := pmreportDesign.Items.Count > 0;
      if pmreportDesign.Items.Count > 0 then
      begin
        ToolButton12.Style := tbsDropDown;
        ToolButton12.DropdownMenu := pmreportDesign;
      end;
    end;

  end;

  procedure TfrmSingle.AddReportVariables(FrpPubPrint: TfrxReport);
  var
    I, j, n, d: integer;
    strVar, strVarName: string;
    tmpComponent: Tcomponent;
  begin
    j := 0;
    d := 0;
    FrpPubPrint.DataSets.Clear;
    FrpPubPrint.Variables.Clear;

    for I := 0 to Self.ComponentCount - 1 do
    begin
      tmpComponent := Self.Components[I];
      if tmpComponent is TfrxDBDataset then
      begin
        if ((TfrxDBDataset(tmpComponent).DataSet <> nil) or (TfrxDBDataset(tmpComponent).DataSource <> nil)) and
          (TfrxDBDataset(tmpComponent).UserName <> '') then
        begin
          // 数据BAND数据源名称
          FrpPubPrint.DataSets.add(TfrxDBDataset(tmpComponent));

          if (TfrxDBDataset(tmpComponent).DataSet <> nil) then
          begin // 直接用数据源
            // 数据控件名
            // if FrpPubPrint.Variables.IndexOf(TfrxDBDataSet(tmpComponent).DataSet.Name)=-1 then
            // begin
            // FrpPubPrint.Variables.Insert(FrpPubPrint.Variables.Count).Name:=TfrxDBDataSet(tmpComponent).DataSet.Name;
            // FrpPubPrint.Variables[TfrxDBDataSet(tmpComponent).DataSet.Name]:=TfrxDBDataSet(tmpComponent).UserName;
            // end;
            // 变量组名
            if FrpPubPrint.Variables.IndexOf(' ' + TfrxDBDataset(tmpComponent).UserName) = -1 then
            begin
              FrpPubPrint.Variables.Insert(FrpPubPrint.Variables.Count).name :=
                ' ' + TfrxDBDataset(tmpComponent).UserName;
              FrpPubPrint.Variables[' ' + TfrxDBDataset(tmpComponent).UserName] := TfrxDBDataset(tmpComponent).UserName;
            end;
            for n := 0 to TfrxDBDataset(tmpComponent).DataSet.FieldCount - 1 do
            begin
              if (TfrxDBDataset(tmpComponent).DataSet.Fields[n].DisplayLabel <> '') and
                (pos('#', TfrxDBDataset(tmpComponent).DataSet.Fields[n].DisplayLabel) = 0) then
              begin
                inc(j);
                if FrpPubPrint.Variables.IndexOf(TfrxDBDataset(tmpComponent).DataSet.name + '.' +
                  TfrxDBDataset(tmpComponent).DataSet.Fields[n].FieldName) = -1 then
                  FrpPubPrint.Variables[TfrxDBDataset(tmpComponent).DataSet.name + '.' + TfrxDBDataset(tmpComponent)
                    .DataSet.Fields[n].FieldName] := TfrxDBDataset(tmpComponent).DataSet.Fields[n].DisplayLabel;

                if FrpPubPrint.Variables.IndexOf(TfrxDBDataset(tmpComponent).UserName + '."' +
                  TfrxDBDataset(tmpComponent).DataSet.Fields[n].DisplayLabel + '"') = -1 then
                begin
                  try
                    FrpPubPrint.Variables.Insert(FrpPubPrint.Variables.Count).name := TfrxDBDataset(tmpComponent)
                      .UserName + '."' + TfrxDBDataset(tmpComponent).DataSet.Fields[n].DisplayLabel + '"';
                    FrpPubPrint.Variables[TfrxDBDataset(tmpComponent).UserName + '."' + TfrxDBDataset(tmpComponent)
                      .DataSet.Fields[n].DisplayLabel + '"'] := TfrxDBDataset(tmpComponent).DataSet.name + '."' +
                      TfrxDBDataset(tmpComponent).DataSet.Fields[n].FieldName + '"';
                  except

                  end;
                end;
              end;
            end;
          end
          else // 间接用数据源
          begin
            // 数据控件名
            // if FrpPubPrint.Variables.IndexOf(TfrxDBDataSet(tmpComponent).DataSource.DataSet.Name )=-1 then
            // begin
            // FrpPubPrint.FieldAliases.Insert(FrpPubPrint.Dictionary.FieldAliases.Count,TfrxDBDataSet(tmpComponent).DataSource.DataSet.Name);
            // FrpPubPrint.FieldAliases[TfrxDBDataSet(tmpComponent).DataSource.DataSet.Name]:=TfrxDBDataSet(tmpComponent).UserName;
            // end;
            // 变量组名
            if FrpPubPrint.Variables.IndexOf(' ' + TfrxDBDataset(tmpComponent).UserName) = -1 then
            begin
              FrpPubPrint.Variables.Insert(FrpPubPrint.Variables.Count).name :=
                ' ' + TfrxDBDataset(tmpComponent).UserName;
              FrpPubPrint.Variables[' ' + TfrxDBDataset(tmpComponent).UserName] := TfrxDBDataset(tmpComponent).UserName;
            end;
            for n := 0 to TfrxDBDataset(tmpComponent).DataSource.DataSet.FieldCount - 1 do
            begin
              if (TfrxDBDataset(tmpComponent).DataSource.DataSet.Fields[n].DisplayLabel <> '') and
                (pos('#', TfrxDBDataset(tmpComponent).DataSource.DataSet.Fields[n].DisplayLabel) = 0) then
              begin
                inc(j);
                // if FrpPubPrint.FieldAliases.IndexOf(TfrxDBDataSet(tmpComponent).DataSource.DataSet.Name+'.'+TfrxDBDataSet(tmpComponent).DataSource.DataSet.Fields[n].FieldName )=-1 then
                // FrpPubPrint.FieldAliases[TfrxDBDataSet(tmpComponent).DataSource.DataSet.Name+'.'+TfrxDBDataSet(tmpComponent).DataSource.DataSet.Fields[n].FieldName ]:=TfrxDBDataSet(tmpComponent).DataSource.DataSet.Fields[n].DisplayLabel ;
                if FrpPubPrint.Variables.IndexOf(TfrxDBDataset(tmpComponent).UserName + '."' +
                  TfrxDBDataset(tmpComponent).DataSource.DataSet.Fields[n].DisplayLabel + '"') <> -1 then
                begin
                  try
                    FrpPubPrint.Variables.Insert(FrpPubPrint.Variables.Count).name := TfrxDBDataset(tmpComponent)
                      .UserName + '."' + TfrxDBDataset(tmpComponent).DataSource.DataSet.Fields[n].DisplayLabel + '"';
                    FrpPubPrint.Variables[TfrxDBDataset(tmpComponent).UserName + '."' + TfrxDBDataset(tmpComponent)
                      .DataSource.DataSet.Fields[n].DisplayLabel + '"'] := TfrxDBDataset(tmpComponent)
                      .DataSource.DataSet.name + '."' + TfrxDBDataset(tmpComponent).DataSource.DataSet.Fields[n]
                      .FieldName + '"';
                  except
                  end;
                end;
              end;
            end;
          end;
          inc(j);
        end;
      end; // end if self.Components[i] is TfrDBDataSet then
    end; // end for

    // 加入其它变量
    for n := low(ArrOtherVar) to high(ArrOtherVar) do
    begin
      if FrpPubPrint.Variables.IndexOf(ArrOtherVar[n]) = -1 then
        FrpPubPrint.Variables.Insert(FrpPubPrint.Variables.Count).name := ArrOtherVar[n];
    end;

  end;

  procedure TfrmSingle.DoAfterPrint;
  begin
    // 打印后的事件  要在子类中去实现
  end;

  procedure TfrmSingle.DoBeforePrint;
  begin
    // 打印前的事件  要在子类中去实现
  end;

  procedure TfrmSingle.FDQryMasterAfterScroll(DataSet: TDataSet);
  begin
    inherited;
    //
    if IfCheck and (StrCheckUser <> '') then
    begin
      ActCheck.Visible := FDQryMaster.FieldByName(StrCheckUser).AsString = '';
      ActUnCheck.Visible := not ActCheck.Visible;
    end
    else
    begin
      ActCheck.Visible := false;
      ActUnCheck.Visible := false;
    end;
    if IfApprove and (StrApporeUser <> '') then
    begin
      ActApprove.Visible := FDQryMaster.FieldByName(StrApporeUser).AsString = '';
      ActUnApprove.Visible := not ActApprove.Visible;
    end
    else
    begin
      ActApprove.Visible := false;
      ActUnApprove.Visible := false;
    end;
    if IfAuditor and (StrAuditUser <> '') then
    begin
      ActAudit.Visible := FDQryMaster.FieldByName(StrAuditUser).AsString = '';
      ActUnAudit.Visible := not ActAudit.Visible;
    end
    else
    begin
      ActAudit.Visible := false;
      ActUnAudit.Visible := false;
    end;

    if IfClose and (StrCloseUser <> '') then
    begin
      ActClose.Visible := FDQryMaster.FieldByName(StrCloseUser).AsString = '';
      ActUnClose.Visible := not ActClose.Visible;
    end
    else
    begin
      ActClose.Visible := false;
      ActUnClose.Visible := false;
    end;

    // 操作条上的间隔条的显示控制
    tbseparator1.Visible := ActAdd.Visible or ActEdit.Visible or ActDel.Visible or ActRefresh.Visible;
    tbseparator2.Visible := ActCheck.Visible or ActApprove.Visible or ActAudit.Visible or ActUnCheck.Visible or
      ActUnApprove.Visible or ActUnAudit.Visible or ActClose.Visible or ActUnClose.Visible;
    tbseparator3.Visible := ActExport.Visible or ActDesign.Visible or ActPrint.Visible;
    tbseparator4.Visible := ActFrist.Visible or ActPrevious.Visible or ActNext.Visible or ActLast.Visible;
  end;

  procedure TfrmSingle.FDQryMasterNewRecord(DataSet: TDataSet);
  var
    I: integer;
    tmpfield: TField;
  begin
    inherited;
    for I := 0 to DataSet.FieldCount - 1 do
    begin
      if DataSet.Fields[I] is TStringField then // 单字节
        DataSet.Fields[I].AsString := '';

      if DataSet.Fields[I] is TWideStringField then // 双字节
        DataSet.Fields[I].AsWideString := '';

      // 数值类型
      if (DataSet.Fields[I] is TNumericField) and not(DataSet.Fields[I] is TAutoIncField) then
        DataSet.Fields[I].asinteger := 0;

      if DataSet.Fields[I] is TBooleanField then // 布尔类型
        DataSet.Fields[I].asboolean := false;
    end;

    if StrCreateUser<>'' then
    begin
      DataSet.FieldByName(StrCreateUser).AsString := UserName;
    end;

    if StrCreatetime<>'' then
    begin
      DataSet.FieldByName(StrCreatetime).AsDateTime := now();
    end;

  end;

  procedure TfrmSingle.FDQryModuleReportNewRecord(DataSet: TDataSet);
  begin
    inherited;
    DataSet.FieldByName('MDR_CODE').AsString := Self.name + format('000', [DataSet.RecordCount + 1]);
    DataSet.FieldByName('MDR_IfDefault').asboolean := false;
    DataSet.FieldByName('MDR_IfUsed').asboolean := false;
    DataSet.FieldByName('MDR_Index').asinteger := DataSet.RecordCount + 1;
    // 写模块编号
    DataSet.FieldByName('MOD_Code').AsString := Self.name;

  end;

  procedure TfrmSingle.FormCreate(Sender: TObject);
  begin
    inherited;
    FOldSearchSQL := FDQryMaster.SQL.Text;
  end;

  procedure TfrmSingle.FormShow(Sender: TObject);
  begin
    inherited;
    FDQryModuleQuery.Close;
    FDQryModuleQuery.ParamByName('mod_code').Value := Name;
    FDQryModuleQuery.Open();

    FDQryModuleFields.Close;
    FDQryModuleFields.ParamByName('mod_code').Value := Name;
    FDQryModuleFields.Open();

    AddReportMenu();

    // 操作条上的间隔条的显示控制
    tbseparator1.Visible := ActAdd.Visible or ActEdit.Visible or ActDel.Visible or ActRefresh.Visible;
    tbseparator2.Visible := ActCheck.Visible or ActApprove.Visible or ActAudit.Visible or ActUnCheck.Visible or
      ActUnApprove.Visible or ActUnAudit.Visible or ActClose.Visible or ActUnClose.Visible;
    tbseparator3.Visible := ActExport.Visible or ActDesign.Visible or ActPrint.Visible;
    tbseparator4.Visible := ActFrist.Visible or ActPrevious.Visible or ActNext.Visible or ActLast.Visible;

    if FDQryMaster.Active and (FDQryMaster.RecordCount > 0) then
      FDQryMasterAfterScroll(FDQryMaster);
  end;

  procedure TfrmSingle.frxReportGetValue(const VarName: string; var Value: Variant);
  begin
    if (CompareText(VarName, ArrOtherVar[1]) = 0) or (CompareText(VarName, 'Companyname') = 0) then
      Value := UserCompany;
    if (CompareText(VarName, ArrOtherVar[2]) = 0) or (CompareText(VarName, 'CompanyTel') = 0) then
      Value := CompanyTel;
    if (CompareText(VarName, ArrOtherVar[3]) = 0) or (CompareText(VarName, 'CompanyFax') = 0) then
      Value := CompanyFax;
    if (CompareText(VarName, ArrOtherVar[4]) = 0) or (CompareText(VarName, 'CompanyAddress') = 0) then
      Value := CompanyAddress;
    if (CompareText(VarName, ArrOtherVar[5]) = 0) or (CompareText(VarName, 'UserName') = 0) then
      Value := UserName;
    if (CompareText(VarName, ArrOtherVar[6]) = 0) or (CompareText(VarName, 'CEO') = 0) then
      Value := CompanyCEO;
    if (CompareText(VarName, ArrOtherVar[7]) = 0) or (CompareText(VarName, 'CFO') = 0) then
      Value := CompanyCFO;
    // 可以加入系统参数生成变量

  end;

  function TfrmSingle.frxSaveReportEvent(Report: TfrxReport; SaveAs: Boolean): Boolean;
  var
    reportstream: TMemoryStream;
  begin
    // 保存报表
    reportstream := TMemoryStream.Create;
    Report.SaveToStream(reportstream);
    reportstream.Position := 0;
    FDQryModuleReport.Edit;
    TBlobField(FDQryModuleReportMDR_Data).LoadFromStream(reportstream);
    FDQryModuleReport.Post;
    // 考虑到总在线读取不方便，最好是存入本地。判断更新时间与本地文件时间决定是读取本地还是在线读取。
    // FDQryModuleReportMDR_Data.SaveToFile(reportPath+'');
    SaveAs := true;
  end;

  procedure TfrmSingle.N3Click(Sender: TObject);
  var
    n: integer;
    ExcelApp: TExcelApplication;
    Workbook: TExcelWorkbook;
    Worksheet: TExcelWorksheet;
    FieldNames: TStringList;
    Row, Col: integer;
    FieldValues:string;
  begin
    inherited;
    // 导出导入模板


      // 创建EXCEL应用程序对象
      {ExcelApp := TExcelApplication.Create(nil);
      ExcelApp.Connect;

      Workbook := ExcelApp.Workbooks.Open('excelfilepath');
      Worksheet := Workbook.Worksheets[1];

      // 获取 Excel 表格字段名
      FieldNames := TStringList.Create;
      for Col := 1 to Worksheet.UsedRange.Columns.Count do
        FieldNames.add(Worksheet.Cells[1, Col].Value);

      // 插入 Excel 数据到数据库
      for Row := 2 to Worksheet.UsedRange.Rows.Count do
      begin


        // 构建字段值
        FieldValues := '';
        for Col := 1 to Worksheet.UsedRange.Columns.Count do
        begin
          if Col > 1 then
            FieldValues := FieldValues + ', ';
          FieldValues := FieldValues + QuotedStr(Worksheet.Cells[Row, Col].Value);
        end;



      end;   }

  end;

  procedure TfrmSingle.N6Click(Sender: TObject);
  begin
    inherited;
    if EnterAddReport(FDQryModuleReport) then
    begin
      // 如果有增加，要重新更新打印和设计菜单
    end;
  end;

  procedure TfrmSingle.pmDesignClick(Sender: TObject);
  var
    CurpageIndex: integer; // 保存主从表显示页面的现场
    reportstream: TMemoryStream;
    frxDesigner: TfrxDesigner;
  ResourceString
    RaiseStr0 = '未定位到相关报表数据，请与技术员联系！';
  begin
    // 设计报表
    if FDQryModuleReport.Active then
      FDQryModuleReport.Open();
    try
      // 在此定位报表
      if not FDQryModuleReport.Locate('MDR_CODE', copy(TMenuItem(Sender).name, 2, 50), []) then
      begin
        showmessage(RaiseStr0);
        abort
      end;
      // 考虑到总在线读取不方便，最好是存入本地。判断更新时间与本地文件时间决定是读取本地还是在线读取。
      frxReport1.Clear;
      if not FDQryModuleReportMDR_Data.IsNull then
      begin
        FDQryModuleReport.FetchBlobs;
        reportstream := TMemoryStream.Create;
        FDQryModuleReportMDR_Data.SaveToStream(reportstream);
        reportstream.Position := 0;
        frxReport1.LoadFromStream(reportstream);
      end;
      try
        frxDesigner := TfrxDesigner.Create(Self);
        frxDesigner.OnSaveReport := frxSaveReportEvent;

        AddReportVariables(frxReport1);
        frxReport1.OnGetValue := frxReportGetValue;
        DoBeforePrint;
        frmReportPreview := TfrmReportPreview.Create(Self);
        frmReportPreview.FastRP := frxReport1;
        frxReport1.Preview := frmReportPreview.frxPreview;
        frxReport1.DesignReport;

      finally
        frxDesigner.Free;
      end;
    finally
      DoAfterPrint;
      frmReportPreview.Free;
      frmReportPreview := nil;
    end;
  end;

  procedure TfrmSingle.pmPrintClick(Sender: TObject);
  // 点击打印或设计菜单弹出打印或设计窗口
  var
    CurpageIndex: integer; // 保存主从表显示页面的现场
    reportstream: TMemoryStream;
  ResourceString
    RaiseStr0 = '未定位到相关报表数据，请与世鸿科技技术员联系！';
    RaiseStr1 = '该记录还未【提交】，不能进行【打印】！';
    RaiseStr2 = '该记录还未【审核】，不能进行【打印】！';
    RaiseStr3 = '该记录还未【记帐】，不能进行【打印】！';
    RaiseStr4 = '该记录已【取消】，不能进行【打印】！';
    RaiseStr5 = '打印';
  begin

    // 已取消的不能打印
    if Trim(StrCancelUser) <> '' then
    begin
      if frxDBDSMaster.DataSet.FieldByName(Trim(StrCancelUser)).AsString <> '' then
        raise Exception.Create(RaiseStr4);
    end;
    // 未提交的不能打印
    if Trim(StrCheckUser) <> '' then
    begin
      if frxDBDSMaster.DataSet.FieldByName(Trim(StrCheckUser)).AsString = '' then
        raise Exception.Create(RaiseStr1);
    end;

    // 未审核的不能打印
    if Trim(StrApporeUser) <> '' then
    begin
      if frxDBDSMaster.DataSet.FieldByName(Trim(StrApporeUser)).AsString = '' then
        raise Exception.Create(RaiseStr2);
    end;

    // 未记帐的不能打印
    if Trim(StrAuditUser) <> '' then
    begin
      if frxDBDSMaster.DataSet.FieldByName(Trim(StrAuditUser)).AsString = '' then
        raise Exception.Create(RaiseStr3);
    end;

    try
      frxReport1.Clear;
      // 考虑到总在线读取不方便，最好是存入本地。判断更新时间与本地文件时间决定是读取本地还是在线读取。
      if not FDQryModuleReportMDR_Data.IsNull then
      begin
        FDQryModuleReport.FetchBlobs;
        reportstream := TMemoryStream.Create;

        FDQryModuleReportMDR_Data.SaveToStream(reportstream);
        reportstream.Position := 0;
        frxReport1.LoadFromStream(reportstream);
      end;

      AddReportVariables(frxReport1);
      frxReport1.OnGetValue := frxReportGetValue;
      DoBeforePrint;
      frmReportPreview := TfrmReportPreview.Create(Self);
      frmReportPreview.FastRP := frxReport1;
      frxReport1.Preview := frmReportPreview.frxPreview;
      frxReport1.ShowReport;
      frmReportPreview.ShowModal;
    finally
      DoAfterPrint;
      frmReportPreview.Free;
      frmReportPreview := nil;
    end;

  end;

  procedure TfrmSingle.QueryAndGridSet;
  begin
    FDQrySQL.Close;
    FDQrySQL.Params.ParamByName('modulecode').Value := Self.name;
    FDQrySQL.Open;
    FDQrySQL.First;
    while not FDQrySQL.Eof do
    begin

      FDQrySQL.Next;
    end;
  end;

  procedure TfrmSingle.ActDesignExecute(Sender: TObject);
  var
    TmpItem: TMenuItem;
  begin
    inherited;
    // 不能使用窗口以外的界面来设置报表，会引起变量问题，只能是在本页面
    { with TfrmReportDesign.Create(Self) do
      begin
      modcode := Self.name;
      curReport := Self.frxReport1;
      ShowModal;
      Free;
      end; }
    // 修改回来后需要重新刷新打印的菜单内容
    { FDQryModuleReport.First;
      while not FDQryModuleReport.Eof do
      begin

      TmpItem := TMenuItem(Self.FindComponent('D' + Trim(FDQryModuleReportMDR_CODE.AsString)));
      if not Assigned(TmpItem) then
      begin
      TmpItem := TMenuItem.Create(Self);
      TmpItem.name := 'D' + Trim(FDQryModuleReportMDR_CODE.AsString);
      TmpItem.Caption := Trim(FDQryModuleReportMDR_Name.AsString);
      TmpItem.OnClick := pmPrintClick;
      TmpItem.Visible := FDQryModuleReportMDR_IfUsed.asboolean;
      // 前面已判断是否存在，此处可以不用判断了
      // if PopPubPrint.Items.IndexOf(TmpItem)=-1 then
      pmPrint.Items.add(TmpItem)
      end
      else
      begin
      TmpItem.Visible := FDQryModuleReportMDR_IfUsed.asboolean;
      end;
      FDQryModuleReport.Next;
      end;
      ActPrint.Visible := pmPrint.Items.Count > 0;
      if pmPrint.Items.Count > 0 then
      begin
      ToolButton13.Style := tbsDropDown;
      ToolButton13.DropdownMenu := pmPrint;
      end; }
  end;

  procedure TfrmSingle.ActRefreshExecute(Sender: TObject);
  begin
    inherited;
    try
      if FDQryMaster.Active then
      begin
        FDQryMaster.Refresh;
      end
      else
        FDQryMaster.Open;
    except

    end;
  end;

  procedure TfrmSingle.ActStopExecute(Sender: TObject);
  begin
    inherited;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;

  end;

  procedure TfrmSingle.ActUnApproveExecute(Sender: TObject);
  ResourceString
    RaiseStr1 = '当前记录已记账，不能作反审操作！';
  begin
    if StrAuditUser <> '' then
    begin
      if FDQryMaster.FieldByName(StrAuditUser).AsString <> '' then
      begin
        showmessage(RaiseStr1);
        abort;
      end;
    end;
    inherited;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;
    if IfApprove and (StrApporeUser <> '') then
    begin
      FDQryMaster.Edit;
      FDQryMaster.FieldByName(StrApporeUser).Clear;
      FDQryMaster.FieldByName(StrApporetime).Clear;
      FDQryMaster.Post;
    end
    else
    begin
      showmessage('本系统不需要反审此数据或是未设置正确的【反审】内容，请与系统管理员联系');
    end;
    { if StrKeyField <> '' then
      DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
      .AsString]))
      else
      DM.SM_LOG(TAction(Sender).Caption); }
    FDQryMasterAfterScroll(FDQryMaster);
  end;

  procedure TfrmSingle.ActUnAuditExecute(Sender: TObject);
  ResourceString
    RaiseStr1 = '当前记录已完结，不能作销账操作！';
  begin
    if StrCloseUser <> '' then
    begin
      if FDQryMaster.FieldByName(StrCloseUser).AsString <> '' then
      begin
        showmessage(RaiseStr1);
        abort;
      end;
    end;
    inherited;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;
    if IfAuditor and (StrAuditUser <> '') then
    begin
      FDQryMaster.Edit;
      FDQryMaster.FieldByName(StrAuditUser).Clear;
      FDQryMaster.FieldByName(StrAudittime).Clear;
      FDQryMaster.Post;
    end
    else
    begin
      showmessage('本系统不需要销账此数据或是未设置正确的【销账】内容，请与系统管理员联系');
    end;
    { if StrKeyField <> '' then
      DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
      .AsString]))
      else
      DM.SM_LOG(TAction(Sender).Caption); }
    FDQryMasterAfterScroll(FDQryMaster);
  end;

  procedure TfrmSingle.ActUncheckExecute(Sender: TObject);
  ResourceString
    RaiseStr1 = '当前记录已审核，不能作提回操作！';
  begin
    if StrApporeUser <> '' then
    begin
      if FDQryMaster.FieldByName(StrApporeUser).AsString <> '' then
      begin
        showmessage(RaiseStr1);
        abort;
      end;
    end;
    inherited;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;
    if IfCheck and (StrCheckUser <> '') then
    begin
      FDQryMaster.Edit;
      FDQryMaster.FieldByName(StrCheckUser).Clear;
      FDQryMaster.FieldByName(StrCheckTime).Clear;
      FDQryMaster.Post;
    end
    else
    begin
      showmessage('本系统不需要提回此数据或是未设置正确的【提回】内容，请与系统管理员联系');
    end;
    { if StrKeyField <> '' then
      DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
      .AsString]))
      else
      DM.SM_LOG(TAction(Sender).Caption);
    }
    FDQryMasterAfterScroll(FDQryMaster);
  end;

  procedure TfrmSingle.ActUnStopExecute(Sender: TObject);
  begin
    inherited;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;
  end;

  procedure TfrmSingle.ActvalidExecute(Sender: TObject);
  begin
    inherited;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;
  end;

  procedure TfrmSingle.ActExitExecute(Sender: TObject);
  ResourceString
    RaiseStr1 = '当前数据处于编辑状态，你是否要退出当前模块！';
  begin // 使用 QryMaster.UpdatesPending  只判断了主表，判断不了明细是否有修改
    if FDQryMaster.Active and (FDQryMaster.state in dseditmodes) then
    begin
      if MessageDlg(RaiseStr1, mtConfirmation, [mbyes, mbno], 0) = mrNo then
      begin
        abort;
      end;
    end;
    inherited;
  end;

  procedure TfrmSingle.ActinvalidExecute(Sender: TObject);
  begin
    inherited;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;
  end;

  procedure TfrmSingle.ActExportExecute(Sender: TObject);
  begin
    inherited;
    DM.SM_LOG(format(ExportDataMSG, [Self.Caption]));
  end;

  procedure TfrmSingle.ActUncloseExecute(Sender: TObject);
  begin
    inherited;
    if not FDQryMaster.Active or FDQryMaster.IsEmpty then
      abort;
    if IfClose and (StrCloseUser <> '') then
    begin
      FDQryMaster.Edit;
      FDQryMaster.FieldByName(StrCloseUser).Clear;
      FDQryMaster.FieldByName(StrClosetime).Clear;
      FDQryMaster.Post;
    end
    else
    begin
      showmessage('本系统不需要反结此数据或是未设置正确的【完结】内容，请与系统管理员联系');
    end;
    { if StrKeyField <> '' then
      DM.SM_LOG(format(OperationBillMESG, [TAction(Sender).Caption, Self.Caption, FDQryMaster.FieldByName(StrKeyField)
      .AsString]))
      else
      DM.SM_LOG(TAction(Sender).Caption);
    }
    FDQryMasterAfterScroll(FDQryMaster);
  end;

end.
